//
//  NetworkManager.h
//  BaseLib
//
//  Created by CPX on 2018/5/21.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "NetworkManager.h"

//for reponse error
//extern NSErrorDomain const AppErrorDomin;
//extern NSInteger const AppResponseFailureCode;
//extern NSString *const AppResponseFailureText;
//
//typedef void(^Success)(id response);
//typedef void(^Failure)(NSError *error);
//typedef void (^DownloadProgress)(NSProgress *downloadProgress);
//typedef NSURL * (^Destination)(NSURL *targetPath, NSURLResponse *response);
//typedef void(^CompletionHandler)(NSURLResponse *response, NSURL *filePath, NSError *error);

/**
 网络库封装V3
 @author yzl
 */
@interface NetworkManagerV3 : NSObject

@property (nonatomic, strong) NSMutableDictionary *keyForTask;

+ (instancetype)sharedManager;


/**
 GET请求
 
 @param url url
 @param params 参数
 @param success 成功
 @param failure 失败
 */
+ (void)GETWithURL:(NSString*)url params:(NSDictionary*)params success:(Success)success failure:(Failure)failure;


/**
 GET请求

 @param url url
 @param headers 头参数
 @param params 参数
 @param success 成功
 @param failure 失败
 */
+ (void)GETWithURL:(NSString*)url header:(NSDictionary*)headers params:(NSDictionary*)params success:(Success)success failure:(Failure)failure;


/**
 GET请求
 
 @param url url
 @param headers 头参数
 @param params 参数
 @param success 成功
 @param failure 失败
 @param name 自定义名称
 */
+ (void)GETWithURL:(NSString*)url header:(NSDictionary*)headers params:(NSDictionary*)params success:(Success)success failure:(Failure)failure name:(NSString*)name;


/**
 PUT请求

 @param url url
 @param headers 头参数
 @param params 参数
 @param success 成功
 @param failure 失败
 */
+ (void)PUTWithURL:(NSString*)url header:(NSDictionary*)headers params:(NSDictionary*)params success:(Success)success failure:(Failure)failure;


/**
 PUT请求

 @param url url
 @param headers 头参数
 @param params 参数
 @param formParams form参数
 @param success 成功
 @param failure 失败
 */
+ (void)PUTWithURL:(NSString *)url header:(NSDictionary *)headers params:(NSDictionary *)params formParams:(NSDictionary*)formParams success:(Success)success failure:(Failure)failure;

/**
 GET请求
 
 @param url url
 @param params 参数
 @param progress 进度
 @param success 成功
 @param failure 失败
 */
+ (void)GETWithURL:(NSString*)url params:(NSDictionary*)params progress:(DownloadProgress)progress success:(Success)success failure:(Failure)failure;


/**
 GET下载

 @param url url
 @param headers 头参数
 @param params 参数
 @param progress 进度
 @param success 成功
 @param failure 失败
 */
+ (void)GETWithURL:(NSString *)url header:(NSDictionary*)headers params:(NSDictionary *)params  progress:(DownloadProgress)progress success:(Success)success failure:(Failure)failure;


/**
 POST请求
 
 @param url url
 @param params 参数
 @param success 成功
 @param failure 失败
 */
+ (void)POSTWithURL:(NSString*)url params:(NSDictionary*)params success:(Success)success failure:(Failure)failure;


/**
 POST请求

 @param url url
 @param headers 头参数
 @param params 参数
 @param success 成功
 @param failure 失败
 */
+ (void)POSTWithURL:(NSString*)url header:(NSDictionary*)headers params:(NSDictionary*)params success:(Success)success failure:(Failure)failure;


/**
 下载

 @param url url
 @param progress 进度
 @param destination 目标位置
 @param completion 完成
 @param name 自定义名称
 */
+ (void)DownloadFile:(NSString*)url progress:(DownloadProgress)progress destination:(Destination)destination completionHandler:(CompletionHandler)completion name:(NSString*)name;

/**
 开始监测网络
 */
- (void)startMonitoring;

/**
 停止监测网络
 */
- (void)stopMonitoring;


/**
 取消请求

 @param name 名称
 */
- (void)cancelTask:(NSString*)name;

@end
